package com.potato.model1.contract;

import com.potato.base.base.BasePresenter;
import com.potato.base.observer.BaseObserver;
import com.potato.model1.bean.CategoryResult;
import com.potato.network.bean.BaseEntity;
import com.potato.network.compat.SchedulersCompat;

import java.util.List;

public class HomeSubPresenter extends BasePresenter<HomeSubContract.MainView, HomeSubModel>{

    @Override
    public HomeSubModel createModel() {
        return new HomeSubModel();
    }

    public void getDank(String category, String pageSize, String page){
        //这儿还没有对Observable进行统一管理
        getModel().getGankData(category,pageSize,page)
                .compose(SchedulersCompat.applyIoSchedulers())
                .subscribe(new BaseObserver<List<CategoryResult>>(getIView()){
                    @Override
                    public void onSuccess(BaseEntity<List<CategoryResult>> result) {
                        if (result != null) {
                            if (getIView()!=null)
                                getIView().showData(result.results);
                        }
                    }
                    @Override
                    public void onError(String errMsg) {
                        if (getIView()!=null)
                            getIView().showError(errMsg);
                    }
                });
    }

}
